<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form>
        <input type="text" id="time"/>   
        <input type="button" value="暂停" onclick="clearTimer()"/>    
        <input type="button" value="继续" onclick="setTimer()"/>
    </form>
    <script>
        var timer;
        var time = document.getElementById('time')
        function day(){
            timer = setInterval(function(){
                var date = new Date()       
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                var hours = date.getHours();
                if(hours < 10){
                    hours = '0' + hours
                }
                var minutes = date.getMinutes()
                if(minutes < 10){
                    minutes = '0' + minutes
                }
                var seconds = date.getSeconds()
                if(seconds < 10){
                    seconds = '0' + seconds
                }
                time.value = year + '年' +month + '月' + day +'日' + ' '+hours +':'+minutes+':'+seconds           
            },1000)
        }

        // 调用函数 显示日期和时间
        day();

        function clearTimer(){
            clearInterval(timer);
        }
        function setTimer(){
            day();
        }
    </script>
</body>
</html>